package kr.ac.skhu.m.controller;

import java.io.PrintWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.ac.skhu.m.data.IndexBoardData;
import kr.ac.skhu.m.data.IndexInfoData;
import kr.ac.skhu.m.data.SkhuNewsData;
import kr.ac.skhu.m.value.InfoValue;
import kr.ac.skhu.m.value.NoticeListValue;

import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;
import net.htmlparser.jericho.Source;

import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 * 인덱스 컨트롤러
 * @author han
 *
 */
public class RentalYnC extends AbstractController {
	
	private String successView;
	
	public void setSuccessView(String successView) {
		this.successView = successView;
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		ModelAndView mav = new ModelAndView(successView);
		
		String book_id = ServletRequestUtils.getStringParameter(request, "book_id", "");
		
		//대여여부
		String detailUrl = "http://library.skhu.ac.kr/DLiWeb20/components/searchir/detail/detail.aspx?cid=" + book_id;
		Source detailSource = new Source(new URL(detailUrl));
		detailSource.fullSequentialParse();
		List<Element> td_white_left = detailSource.getAllElementsByClass("td_white_left");
		
		String rentalYn = "";
		
		try{
			rentalYn = td_white_left.get(1).getTextExtractor().toString();
		}catch(Exception e){
			rentalYn = "";
		}
		
		mav.addObject("rentalYn", rentalYn);
		
		return mav;
	}
	
}
